// pages/check/gysenter/gysenter.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		region: ['', '', ''],
		map: '',
		name: '',
		mobile: '',
		text1: '',
		id: [],
		zt: false,
		index: '',
		http: getApp().globalData.map,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid
				})
				wx.request({
					url: getApp().globalData.chang + 'action=getShopInfo&uid=' + e.data.uid,
					success: (e) => {
						console.log(e)
						let a = []
						let c = []
						e.data.data.ServerType.forEach(function(item, index) {
							a.push(item)
							c.push('')
						})
						console.log(c)
						this.setData({
							array: a,
							img:e.data.data.shopInfo.ShopImage,
							data: e.data.data,
							id: c
						})
					}
				})
			}
		})
	},
	img() {
		let that = this
		wx.chooseImage({
			count: 1,
			sizeType: 'compressed',
			success: (e) => {
				console.log(e)
				let a = this.data.data
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: e.tempFilePaths[0],
					name: 'picturePath',
					success: function(res) {
						let c = JSON.parse(res.data)
						let img=c.data.headImage
						a.shopInfo.ShopImage = getApp().globalData.map + c.data.headImage
						that.setData({
							data: a,
							img:img,
							http: ''
						})
						console.log(that.data.data)
					},
				})
			}
		})
	},
	name(e) {
		let a = this.data.data
		a.RealName = e.detail.value
		this.setData({
			data: a
		})
	},
	mobile(e) {
		let a = this.data.data
		a.Mobile = e.detail.value
		this.setData({
			data: a
		})
	},
	brief(e) {
		let a = this.data.data
		a.Remark = e.detail.value
		this.setData({
			data: a
		})
	},
	xz(e) {
		console.log(e)
		let a = this.data.id
		let c = e.currentTarget.dataset
		if (a[c.index] == '') {
			a[c.index] = c.id
		} else {
			a[c.index] = ''
		}
		console.log()
		this.setData({
			id: a
		})
	},
	sure() {
		let that = this
		let a = this.data.data.shopInfo
		let da = that.data.id
		let c=[]
		da.forEach(function(item,index){
			if(item!=''){
				c.push(item)
			}
		})
		c=c.join()
		console.log(c)
		console.log(this.data.img)
		wx.request({
			url: getApp().globalData.chang + 'action=updateShopInfo&uid=' + that.data.uid + '&mobile=' + a.Mobile +
				'&shopInfo=' +
				a.Remark + '&realName=' + a.RealName + '&shopImg=' + this.data.img + '&serverType=' + c,
			success: (e) => {
				console.log(e)
				wx.navigateBack({
					delta: 1
				})
			}
		})
	}
})
